package com.janyee.powerdroidtest

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import com.alibaba.fastjson.JSON

import com.alibaba.fastjson.JSONObject
import com.janyee.powerdroid.http.JsonRequest
import com.janyee.powerdroid.http.callback.JsonCallBack
import com.janyee.powerdroid.http.callback.StringCallBack
import okhttp3.Response

import java.io.IOException

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val jsonObject = JSONObject()
        jsonObject.put("email", "kmlixh@foxmail.com")
        jsonObject.put("pwd", "")
        val callback = object : StringCallBack<Int>() {
            override fun workOnBackThread(jsonObject: String?, e: Exception?): String? {
                return jsonObject
            }

            override fun workOnUiThread(r: String?) {
                Toast.makeText(applicationContext, r!!,Toast.LENGTH_SHORT).show()
            }

            override fun handleProcessOnUiThread(v: Int?) {

            }

        }
        val url = "https://api.timelist.io/login"
        val request = JsonRequest(url, jsonObject, callback)
        MyApplication.s().addAsyncRequest(request)
    }
}
